﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApMovMovieRecorder
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.MovieRecorder;
using System.Collections.Generic;
using System.IO;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApMovMovieRecorder
{
  private TxMovieRecorder m_movieRecorder;
  private TxViewerRecordingSettings m_settings;
  private CApMRCRecorderSettings m_recorderSettings;
  private string m_fileFormat = ".avi";

  public CApMovMovieRecorder() => this.m_movieRecorder = TxApplication.MovieRecorder;

  private List<TxMovieOverlay> CreateOverlays()
  {
    List<TxMovieOverlay> overlays = new List<TxMovieOverlay>();
    if (this.Settings.OverlayImagePath != string.Empty)
      overlays.Add((TxMovieOverlay) new TxMovieImageOverlay(this.Settings.OverlayImagePath, this.Settings.OverlayImageWidth.Percent(this.Settings.OverlayImageSizePercent), this.Settings.OverlayImageHeight.Percent(this.Settings.OverlayImageSizePercent), this.Settings.OverlayImageTransparency, this.Settings.OverlayPosition));
    if (this.Settings.OverlayText != string.Empty)
      overlays.Add((TxMovieOverlay) new TxMovieTextOverlay(this.Settings.OverlayText, this.Settings.OverlayFontSize, this.Settings.ToColor(this.Settings.OverlayFontColor), this.Settings.ToColor(this.Settings.OverlayFontShadowColor), this.Settings.OverlayPosition));
    return overlays;
  }

  public CApMRCRecorderSettings Settings
  {
    get => this.m_recorderSettings;
    set
    {
      this.m_recorderSettings = value;
      this.m_recorderSettings.ChangeSimulationTimeInterval = false;
      this.m_recorderSettings.FileDestination = string.Empty;
      this.m_settings = new TxViewerRecordingSettings("", (ITxViewerRecordingSource) TxApplication.ViewersManager.GraphicViewer, this.Settings.ResolutionWidth, this.Settings.ResolutionHeight);
      ((TxMovieRecordingSettings) this.m_settings).Codec = this.Settings.Codec;
      ((TxMovieRecordingSettings) this.m_settings).Compression = this.Settings.Compression;
      ((TxMovieRecordingSettings) this.m_settings).FrameRate = this.Settings.FrameRate;
      this.m_settings.TimeSource = (TxMovieTimeSource) 1;
      ((TxMovieRecordingSettings) this.m_settings).AddOverlays(this.CreateOverlays());
      this.m_fileFormat = "." + this.Settings.FileFormat;
    }
  }

  public bool IsActive => this.m_movieRecorder != null && this.m_movieRecorder.State == 1;

  public void StartRecording(string filePath)
  {
    if (this.m_movieRecorder == null)
      return;
    FileInfo fileInfo = new FileInfo(filePath);
    if (!fileInfo.Directory.Exists)
      fileInfo.Directory.Create();
    ((TxMovieRecordingSettings) this.m_settings).FilePath = filePath;
    this.m_movieRecorder.Start((TxMovieRecordingSettings) this.m_settings);
  }

  public void StopRecording()
  {
    if (this.m_movieRecorder == null)
      return;
    this.m_movieRecorder.Stop();
  }

  public string MovieFileExtension => this.m_fileFormat;
}
